/*
 ============================================================================
 Name		: DocXmlParser.h
 Author	  : JohnLZeng
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CDocXmlParser declaration
 ============================================================================
 */

#ifndef DOCXMLPARSER_H
#define DOCXMLPARSER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include "XmlParseNotify.h"
#include "DefaultDocHandler.h"
#include "DefaultDeclHandler.h"

//_LIT(KDocXmlTagDiv,		"div");	
//_LIT(KDocXmlTagSpan,	"span");	
_LIT(KDocXmlTagP,		"p");	
_LIT(KDocXmlTagA,		"a");	
//_LIT(KDocXmlTagStrong,	"strong");
_LIT(KDocXmlTagBr,		"br");
//_LIT(KDocXmlTagStrong,	"strong");
//_LIT(KDocXmlTagImg,		"img");

//_LIT(KDocXmlAttrId,		"id");

_LIT(KDocXmlAttrHref,		"href");
//_LIT(KDocXmlValueTitle,	"title");
//_LIT(KDocXmlValueContent,"content");

enum TDocXmlTagType
	{
	EDocXmlTagNone = 0,
//	EDocXmlTagDiv,
//	EDocXmlTagSpan,
	EDocXmlTagP,
	EDocXmlTagA,
//	EDocXmlTagStrong,
	EDocXmlTagBr
//	EDocXmlTagImg,
	
//	EDocXmlTagDivTitle,
//	EDocXmlTagDivContent
//	EDocXmlTag
	};

class CRSSBriefData;
// CLASS DECLARATION

/**
 *  CDocXmlParser
 * 
 */
class CDocXmlParser : public CBase, public CDefaultDocHandler
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CDocXmlParser();

	/**
	 * Two-phased constructor.
	 */
	static CDocXmlParser* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CDocXmlParser* NewLC();

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CDocXmlParser();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();
	
public:  //CDefaultDocHandler
	void StartElement(const TQualified& aName, const RArray<TAttribute>& aAttributes);
	void EndElement(const TQualified& aName);
	void CharacterData(const TDesC& aData);
//	void StartCDataSection();
//	void EndCDataSection();

public:
	void Parse(const TDesC8& aBuffer);
	
	void Clear();
	
	void SetParseNotify(MDocXmlParseNotify* aParseNotify) {iParseNotify = aParseNotify;};
	void SetData(CRSSBriefData*	aRSSBriefItem) {iRSSBriefItem = aRSSBriefItem;};
private:
	TInt ConvertTagToNumber(const TDesC& aTag);
	void PushTag(const TInt aTag);
	void PopTag();
	TInt StackTag();
	TInt StackParentTag(TInt aLevel);
	
	void EndParseTagP();
	void ParseDataP(const TDesC& aData);
	void ParseTagA(const RArray<TAttribute>& aAttributes);
	
	void WriteContent();
	
private:	
	MDocXmlParseNotify* iParseNotify;
	
	RArray<TInt>	iTagStack;			
	HBufC8*			iContent;			
	CRSSBriefData*	iRSSBriefItem;		//not owned
	};

#endif // DOCXMLPARSER_H
